
// Qt
#include <QtCore>
#include <QtGui>

// GMQtExt
#include <messageboxes/messageboxes.h>

// local
#include "myglwidget.h"

// header
#include "mainwindow.h"




MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {

  _widget = new MyGLWidget(this);
  setCentralWidget( _widget );

  _scene = _widget;

  QMenu *file_menu = menuBar()->addMenu( tr("&File") );
  QMenu *file_help = menuBar()->addMenu( tr("&Help") );

  QAction *action_openfile = new QAction( tr("&open"), this );
  file_menu->addAction(action_openfile);

  QAction *action_quit = new QAction( tr("&Quit"), this );
  file_menu->addAction(action_quit);

  QAction *action_about_gmlib = new QAction( tr("About &GMlib"), this );
  file_help->addAction(action_about_gmlib);

	Q

  connect( action_openfile, SIGNAL(triggered()), this, SLOT(_slotOpenFile()) );
  connect( action_quit, SIGNAL(triggered()), this, SLOT(_slotQuit()) );
  connect( action_about_gmlib, SIGNAL(triggered()), this, SLOT(_slotAboutGMlib()) );

  _f3d_data = new Flow3DData();
  _myf3dnode = new Flow3DNode();
}

MainWindow::~MainWindow() {}

void MainWindow::_slotOpenFile() {
  QString fileName = QFileDialog::getOpenFileName(this, tr("Open Image"));
	

	if( !fileName.isNull() )
	{
		_f3d_data->load( fileName.toStdString().c_str(), DATA_TYPE_ALL );
		if(_f3d_data->isValid())
		{
				_myf3dnode->setF3DData( _f3d_data );
		}
	}
}

void MainWindow::_slotAboutGMlib() {

  GMQtExt::MessageBoxes::aboutGMlib( centralWidget() );
}

void MainWindow::_slotQuit() {

  // Ask for confirmation on clear
  QMessageBox::StandardButton choice = QMessageBox::question( this, tr("Quit?"), tr("Sure you want to quit?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes );
  switch( choice ) {

    case QMessageBox::No:
      return;
      break;

    case QMessageBox::Yes:
    default:

      // Remove all Selections
      close();
      break;
  }
}

void MainWindow::initScene() {

  _widget->initScene();

  _widget->insert( _myf3dnode );
}

























